﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataTier;
using DataAccessLayer;

namespace BusinessTier
{
    public class BStation : IBStation
    {

        /// <summary>
        /// Returns a List of all the stations in the database.
        /// </summary>
        /// <returns>Returns a List<Station> with all the stations in the database.</Station></returns>

        public List<Station> GetAllStations()
        {
            List<Station> stations = DBStation.GetAllStations();
            List<Edge> edges = DBStation.GetAllEdges();

            foreach (Station station in stations)
            {
                foreach (Edge edge in edges)
                {
                    if(station.StationId == edge.From.StationId)
                    {
                        edge.From = station;
                        station.Edges.Add(edge);
                    }
                    if (station.StationId == edge.To.StationId)
                    {
                        edge.To = station;
                    }
                }

            }


            return stations;
        }

        //public List<Station> GetStations()
        //{
        //    return DBStation.GetStations();
        //}

        public List<Edge> GetAllEdges()
        {
            return DBStation.GetAllEdges();
        }

        public void CreateStation(string name, string address, int zip)
        {
            DBStation.CreateStation(name, address, zip);
        }

        //public List<Station> getSortedStations(int startStationZip)
        //{
        //    List<Station> stations = GetAllStations();
        //    List<Station> sortedStations = new List<Station>();
        //    List<Station> currentStack = new List<Station>();

        //    bool found = false;
        //    int index = 0;

        //    while(found != true || index <= stations.Count)
        //       {
        //           if(startStationZip == stations[index].ZipCode)
        //           {
        //               sortedStations.Add(stations[index]);
        //               currentStack.Add(stations[index]);
        //               stations.Remove(stations[index]);
        //               found = true;
        //           }
        //           else
        //           {
        //               index++;
        //           }

        //    found = false;
        //    index = 0;
        //    while(found != true || index <= stations.Count)
        //    {
        //        foreach(Edge edge in currentStack.)
        //    }

        //    return sortedStations;
        //}




        public void CreateEdge(int fromStation, int toStation, int cost)
        {
            DBStation.CreateEdge(fromStation, toStation, cost);
        }


        public void DeleteStation(int stationId)
        {
            DBStation.DeleteStation(stationId);
        }


        public void DeleteEdgeFrom(int stationId)
        {
            DBStation.DeleteEdgeFrom(stationId);
        }

        public void DeleteEdgeTo(int stationId)
        {
            DBStation.DeleteEdgeTo(stationId);
        }
    }
}
